# -*- coding: utf-8 -*-
'''
@文件    :register.py
@说明    :
@时间    :2025/09/03 15:28:53
@作者    :浪晋
@版本    :1.0
'''
from flask import Flask
from werkzeug.exceptions import BadRequest, NotFound, MethodNotAllowed, Unauthorized
from app.core.hooks import before_request, after_request, finally_request
from app.core.exceptions import bad_request

def add_routes(app: Flask, prefix="/api"):
    """
    @功能    :注册蓝图
    @参数    :
    @返回值  :
    @时间    :2024/10/26 00:27:43
    @作者    :浪晋
    @版本    :1.0
    """
    from app.api.v1 import admin

    app.register_blueprint(admin.router, url_prefix=prefix)


def add_hooks(app: Flask):
    """注册钩子函数"""
    app.before_request(before_request)
    app.after_request(after_request)
    app.teardown_request(finally_request)


def add_exceptions(app: Flask):
    """注册错误处理程序"""
    app.register_error_handler(BadRequest, bad_request)
    app.register_error_handler(Unauthorized, bad_request)
    app.register_error_handler(NotFound, bad_request)
    app.register_error_handler(MethodNotAllowed, bad_request)
    app.register_error_handler(Exception, bad_request)
    

def add_extensions(app: Flask):
    """注册第三方扩展"""
    pass
